<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<title>消息接收</title>
<div style="padding: 10px;">
<table id="messageReceiver" lay-filter="messageReceiver"></table>
<script type="text/html" id="headerToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="mark">
            <i class="layui-icon layui-icon-read"></i>
            <span>标记为已读</span>
        </a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            <span>删除</span>
        </a>
        <button type="clears" class="layui-btn layui-btn-sm " lay-event="clears">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </button>
    </div>
    <form class="layui-form"  lay-filter="queryReceiverForm" style="margin-right: 30px;">
        <div class="layui-row" style="margin-top: 10px;">
            <div class="selch table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label" style="width:66px;padding:9px 3px">标题</label>
                    <input type="text" name="Q_subject_SL" class="layui-input subject filter-value" placeholder="标题"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label" style="width:66px;padding:9px 3px">消息类型</label>
                    <select name="Q_messageType_S" class="layui-input filter-value" value="${param['Q_messageType_S']}" >
                        <option value="">全部</option>
                        <option value="1">个人信息</option>
                        <option value="2" >日程安排</option>
                        <option value="3" >计划任务</option>
                        <option value="4" >系统信息</option>
                        <option value="5" >代办提醒 </option>
                        <option value="6" >流程提醒</option>
                    </select>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label" style="width:66px;padding:9px 3px">是否已读</label>
                    <select  name="Q_receiveTime_S" class="layui-input filter-value">
                     <option value="">全部</option>
                    <option value="1">未读</option>
                    <option value="2">已读</option>
                    </select>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label" style="width:auto">发送时间</label>
                    <input type="text" name="Q_beginreceiveTime_DL" autocomplete="off" placeholder="发送时间"
                           class="layui-input start_time filter-value">
                    <label class="layui-form-label" style="width:auto">至</label>
                    <input type="text" name="Q_endreceiveTime_DG" autocomplete="off" placeholder="结束时间"
                           class="layui-input end_time filter-value">
                </div>
            </div>
        </div>
    </form>

</script>
</div>
<script type="text/html" id="rightToolsBar">
    {{#  if(d.canReply==1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="reply" style="margin-right: 10px;">回复</a>
    {{#  } }}
    <a class="layui-btn layui-btn-xs" lay-event="detail" style="margin-right: 10px;">明细</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="margin-right: 10px;">删除</a>
</script>

<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'util','form', 'laydate', 'setter','totalFilter','commons','common'], function () {
        var util = layui.util;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.jquery;
        var table = layui.table;
        var setter = layui.setter;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var totalFilter = layui.totalFilter;
       var commons=layui.commons;
       var common=layui.common;
        var tableHeight='full-70';
        var tableHeight=commons.tabHeight(tableHeight);
        //第一个实例
        table.render({
            elem: '#messageReceiver'
            , url: serverPath.systemPath +setter.sysLinkPath +'messageReceiver/list'
            , page: true
            ,defaultToolbar: ['filter', 'print']
            , toolbar: '#headerToolsBar'
            , title: '数据库表信息'
            , height:tableHeight
            , method: 'post'
            , cols: [[
                {type: 'checkbox'}
                ,
                {field:'userName',title:'发信人' , sort:true}
                ,
                ,
                {field:'canReply',title:'是否回复', hide:true}
                ,
                {field: 'subject', title: '标题', sort:true},
                {field: 'receiveType', title: '消息来源', templet:function (d) {
                    if(d.receiveType == '0'){
                        return '用户';
                    }
                    if(d.receiveType == '1'){
                        return '组织';
                    }
                }}
                , {field: 'messageType', title: '消息类型',templet: function (d) {
                        if (d.messageType == '1') {
                            return '个人信息';
                        }
                        if (d.messageType == '2') {
                            return '日程安排';
                        }
                        if (d.messageType == '3') {
                            return '计划任务';
                        }
                        if (d.messageType == '4') {
                            return '系统信息';
                        }
                        if (d.messageType == '5') {
                            return '代办提醒';
                        }
                        if (d.messageType == '6') {
                            return '流程提醒';
                        }
                        return '其他';}}
                , {
                    field: 'sendTime', title: '发送时间',
                    sort: true,templet:function(d){
            if (d.sendTime == undefined) {
                return "";
            }else {
                return util.toDateString(d.sendTime, "yyyy-MM-dd HH:mm:ss");
            }
        }
                }
                 , {
                     field: 'receiveTime', title: '收信时间',
                     sort: true,templet:function(d){
                        if (d.receiveTime == undefined) {
                            return "未读消息";
                        }else {
                            return util.toDateString(d.receiveTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                 }
                , {
                    fixed: 'right',
                    align: 'center',
                    title: '操作',
                    toolbar: '#rightToolsBar'
                }
            ]],
            done: function () {
                reflashDate();
                table.resize()
            }
        });
        totalFilter.init('messageReceiver');
        reflashDate();
        /*刷新时间控件*/
        reflashDate();
        /*刷新时间控件*/
        function reflashDate() {
            var start = laydate.render({
                elem: '.start_time',
                type: 'date',
                //format: 'yyyy-MM-dd',
                max: nowTime,
                done: function (value, date, endDate) {
                    endMax = end.config.max;
                    end.config.min = date; //最大时间为结束时间的开始值  
                    end.config.min.month = date.month - 1;
                    $("input[name='start_time']").val(value);
                }
            });
            var end = laydate.render({
                elem: '.end_time',
                type: 'date',
                max: 4073558400000,
                format: 'yyyy-MM-dd',
                // min: nowTime,
                done: function (value, date) {
                    if ($.trim(value) == '') {
                        var curDate = new Date();
                        date = {
                            'date': curDate.getDate(),
                            'month': curDate.getMonth() + 1,
                            'year': curDate.getFullYear()
                        };
                    }
                    start.config.max = date; //最小时间为开始时间的最大值  
                    start.config.max.month = date.month - 1;
                    $("input[name='end_time']").val(value);
                }
            })
        }
        //监听头工具栏事件
        table.on('toolbar(messageReceiver)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        var receiveOrgType = 0;
                        //判断勾选的数据中是否包含消息来源为组织的数据
                        for(var i=0;i<data.length;i++){
                            if(data[i].receiveType === 1){
                                receiveOrgType++;
                            }
                        }
                        //删除的数据为组织时提示不能进行删除
                        if(receiveOrgType > 0){
                            layer.msg("消息来源为组织的数据不能进行删除!");
                            return false;
                        }else{
                            layer.confirm('确定删除当前数据吗？', function () {
                                var seleIds = [];
                                for (var i = 0; i < data.length; i++) {
                                    seleIds.push(data[i].rid);
                                }
                                $.ajax({
                                    url: serverPath.systemPath + setter.sysLinkPath + "messageReceiver/del",
                                    type: "post",
                                    dataType: 'json',
                                    data: {id: seleIds.join(",")},
                                    success: function (data) {
                                        if (commons._filterRecord(data)) {
                                            layer.alert(data.msg);
                                            table.reload('messageReceiver', {
                                                page: {curr: 1, limit: 10},
                                            });

                                            totalFilter.init('messageReceiver');
                                            reflashDate();
                                        } else {
                                            layer.alert(data.msg);
                                        }

                                    }
                                })
                                return false;
                            })
                        }
                    }
                    break;
                    location.reload();

                case 'mark':
                    if (data.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        layer.confirm('确定将信息标记为已读？', function () {
                            var seleIds = [];
                            for (var i = 0; i < data.length; i++) {
                                seleIds.push(data[i].rid);
                            }
                            $.ajax({
                                url: serverPath.systemPath + setter.sysLinkPath + "messageReceiver/mark",
                                type: "post",
                                dataType: 'json',
                                data: {id: seleIds.join(",")},
                                success: function (data) {
                                    if (commons._filterRecord(data)) {
                                        layer.alert(data.msg);
                                        table.reload('messageReceiver', {
                                            page: {curr: 1, limit: 10},
                                        });

                                        totalFilter.init('messageReceiver');
                                        reflashDate();
                                    } else {
                                        layer.alert(data.msg);
                                    }
                                }
                            })
                        return false;
                        });
                    }
                    break;
                case 'clears':
                    common.tableConditionRender("messageReceiver","queryReceiverForm",{where:{}},true);
                    reflashDate();
                    break;
                case 'query':
                    common.tableConditionRender("messageReceiver","queryReceiverForm",{where:{}},false);
                    reflashDate();
                    break;
            }
        });
        common.tableSort("messageReceiver");
//监听行事件
        table.on('tool(messageReceiver)', function (obj) {
            var data = obj.data;
            //根据是否回复设置弹窗大小
            var height='420px';
            if(data.canReply==1){
              height='750px';
            }
            switch (obj.event) {
                case 'detail':
                    layer.open({
                        type: 2,
                        area: ['1000px','585px'],
                        title: ['查看信息明细'],
                        content: serverPath.systemPath + setter.sysLinkPath+'messageRead/view/list?messageId='+data.id,
                        btn: ['关闭'],
                        btnAlign: 'c',
                        skin: 'btn-close',
                        end:function () {
                            table.reload('messageReceiver');
                            totalFilter.init('messageReceiver');
                        }
                    });
                    break;
                case 'reply':
                    layer.open({
                        type: 2,
                        area: ['1000px','480px'],
                        title: ['回复消息'],
                        content: serverPath.systemPath + setter.sysLinkPath+'messageReply/view/edit?messageId='+data.id+"&id=" + data.rid
                    });
                    break;
                    case 'del':
                    if(data.receiveType === 1){
                        layer.msg("消息来源为组织的数据不能进行删除!");
                    }else{
                        layer.confirm('确定删除当前数据吗？',function (index) {
                            layer.close(index);
                            $.ajax({
                                url: serverPath.systemPath + setter.sysLinkPath + "messageReceiver/del",
                                type: "get",
                                dataType: 'json',
                                data: {id: obj.data.rid},
                                success: function (data) {
                                    if (commons._filterRecord(data)) {
                                        layer.alert(data.msg);
                                        table.reload('messageReceiver', {
                                            page: {curr: 1, limit: 10}
                                        });
                                        totalFilter.init('messageReceiver');
                                        reflashDate();
                                    } else {
                                        layer.alert(data.msg);
                                    }
                                }
                            })
                            return false;
                        });
                    }
                    break;
                    location.reload();
            }
        });
            });
</script>
<style>
    .btn-close .layui-layer-btn{
        text-align: center;
    }
    .btn-close .layui-layer-btn a{
        display: inline-block;
        height: 38px;
        line-height: 38px;
        padding: 0 18px;
        background-color: #FF5722;
        color: #fff;
        white-space: nowrap;
        text-align: center;
        font-size: 14px;
        border: none;
        border-radius: 2px;
        cursor: pointer;
    }
    .btn-close .layui-layer-btn0{
        background-color: #FF5722;
    }
</style>
</body>
</html>